package cn.huiyunche.bms.web.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

/**
 * Created by zhaoguixin on 2017/7/10.
 */
@Controller
@RequestMapping("/index")
public class IndexController {

    @RequestMapping()
    public String index(RedirectAttributes attr) throws Exception{
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        String username = (String)session.getAttribute("username");
        attr.addFlashAttribute("username",username);
        return "index";
    }

    @RequestMapping("home")
    public String home() throws Exception{
        return "home";
    }
    //调整金额
    @RequestMapping("adjust")
    public String money(HttpServletResponse response, Model model, HttpServletRequest request) throws Exception{
        BigDecimal sysCost = BigDecimal.valueOf(Double.valueOf(request.getParameter("sysCost"))) ;
        BigDecimal settleCost = BigDecimal.valueOf(Double.valueOf(request.getParameter("settleCost"))) ;
        BigDecimal alterCost = BigDecimal.valueOf(Double.valueOf(request.getParameter("alterCost"))) ;
        String comment = request.getParameter("comment");
        System.out.println("sysCost="+sysCost);
        System.out.println("settleCost="+settleCost);
        System.out.println("alterCost="+alterCost);
        response.setHeader("X-Frame-Options", "SAMEORIGIN");// 解决IFrame拒绝的问题

        model.addAttribute("sysCost",sysCost);
        model.addAttribute("settleCost",settleCost);
        model.addAttribute("alterCost",alterCost);
        model.addAttribute("comment",comment);

        return "adjust";
    }
    //价格距离调整
    @RequestMapping("costAndDistance")
    public String costAndDistance(HttpServletResponse response, Model model, HttpServletRequest request) throws Exception{
        BigDecimal orderCost = BigDecimal.valueOf(Double.valueOf(request.getParameter("orderCost"))) ;
        BigDecimal distance = BigDecimal.valueOf(Double.valueOf(request.getParameter("distance"))) ;
        System.out.println("orderCost="+orderCost);
        System.out.println("distance="+distance);
        response.setHeader("X-Frame-Options", "SAMEORIGIN");// 解决IFrame拒绝的问题

        model.addAttribute("orderCost",orderCost);
        model.addAttribute("distance",distance);

        return "adjust/costAndDistance";
    }
    @RequestMapping("demo1")
    public String demo1() throws Exception{
        return "demo1";
    }
    //应收账单管理
    @RequestMapping("receivable")
    public String receivable() throws Exception{
        return "receivable/receivable";
    }
    @RequestMapping("newBillR")
    public String newBillR() throws Exception{
        return "receivable/newBillR";
    }
    @RequestMapping("generateBillR")
    public String generateBillR() throws Exception{
        return "receivable/generateBillR";
    }
    @RequestMapping("confirmBillR")
    public String confirmBillR() throws Exception{
        return "receivable/confirmBillR";
    }

    //应付账单管理
    @RequestMapping("payable")
    public String payable() throws Exception{
        return "payable/payable";
    }
    @RequestMapping("newBill")
    public String newBill() throws Exception{
        return "payable/newBill";
    }
    @RequestMapping("generateBill")
    public String generateBill() throws Exception{
        return "payable/generateBill";
    }
    @RequestMapping("confirmBill")
    public String confirmBill() throws Exception{
        return "payable/confirmBill";
    }

    //收款管理 proceedManage
    @RequestMapping("proceedManage")
    public String proceedManage() throws Exception{
        return "proceed/proceedManage";
    }
    //收款 proceed
    @RequestMapping("proceed")
    public String proceed() throws Exception{
        return "proceed/proceed";
    }
    //付款管理 paymentManage
    @RequestMapping("paymentManage")
    public String paymentManage() throws Exception{
        return "payment/paymentManage";
    }
    //付款 payment
    @RequestMapping("payment")
    public String payment() throws Exception{
        return "payment/payment";
    }
    //订单价格调整
    @RequestMapping("orderPrice")
    public String orderPrice() throws Exception{
        return "adjust/orderPrice";
    }
    //运单价格调整
    @RequestMapping("wayBillPrice")
    public String wayBillPrice() throws Exception{
        return "adjust/wayBillPrice";
    }
    //销售收款审核
    @RequestMapping("receiptAudit")
    public String receiptAudit() throws Exception{
        return "audit/receiptAuditList";
    }
}
